package com.sanweibook.jhook.server.aop;

import com.sanweibook.jhook.common.ErrorCodeEnum;
import com.sanweibook.jhook.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * Created by twg on 2017/5/17.
 */
@Aspect
@Slf4j
@Component
public class FacadeExceptionAspect {

    @Around(value = "execution(* com.sanweibook.jhook.server.facade..*.*(..)))")
    public Object around(ProceedingJoinPoint joinPoint){
        try {
            return joinPoint.proceed();
        } catch (Throwable throwable) {
            log.error("facade services error.{}",throwable);
        }
        return Result.returnErrorResult(ErrorCodeEnum.REMOTE_SERVICE_ERROR.getCode(),ErrorCodeEnum.REMOTE_SERVICE_ERROR.getMessage());
    }


    /*@AfterThrowing(value = "method()",throwing = "e")
    public void after(JoinPoint joinPoint, Throwable e) {
        System.out.println("=====FacadeExceptionAspect.after====" + joinPoint.getSignature().getName());
        System.out.println("=====FacadeExceptionAspect.after====" + e);
        System.out.println("=====FacadeExceptionAspect.after====" + joinPoint.getTarget());
    }*/
}
